//
//  exchangeDetailVC.swift
//  甜言蜜语
//
//  Created by yingli on 16/7/23.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit
import SVProgressHUD
class exchangeDetailVC: UIViewController {

    var id : Int = 0
    
//    @IBOutlet weak var goodsImg: UIImageView!
//    @IBOutlet weak var goodsName: UILabel!
//    @IBOutlet weak var money: UILabel!
//    @IBOutlet weak var integral: UILabel!
    @IBOutlet weak var webView: UIWebView!
    
    var modelList: integralMallDetailInfo? {
        didSet {
            //let model = modelList
             self.webView.loadHTMLString((self.modelList?.body)!, baseURL: nil)
            
//            self.goodsImg.sd_setImageWithURL(NSURL(string: model!.imgsrc), placeholderImage: UIImage(named: "placeholder"))
//            self.goodsName.text = String(format: "商品名称:%@", (model?.name)!)
//            self.money.text = String(format: "¥%@",(model?.money)!) 
//            self.integral.text = String(format: "所需积分:%@", (model?.integral)!)
            
        }
    }
    var msg: regiestInfo?{
        didSet{
            
        }
    }
    override func viewDidLoad() {
        publicMethod.setHUDStyle()
        DataTool.integralMallDetail(id, completionHandler:{ (newModel) in
            guard let newDataes = newModel else {
                return
            }
               print(newDataes)
            self.modelList = newDataes
            
        })

    }
    
    override func viewWillDisappear(animated: Bool) {
        SVProgressHUD.dismiss()
        super.viewWillDisappear(animated)
    }
    @IBAction func checkIntegral(sender: UIButton){
        DataTool.checkIntegralNum(id, completionHandler: { (newModel) in
            guard let newDataes = newModel else {
                return
            }
            print(newDataes)
            self.msg = newDataes
            if self.msg!.msg == "可以兑换"{
                
                let vc = self.storyboard?.instantiateViewControllerWithIdentifier("securityVerificationVC") as! securityVerificationVC
                vc.id = self.id
                vc.type = "积分"
                self.navigationController?.pushViewController(vc, animated: true)
            }else{
                SVProgressHUD.showErrorWithStatus(self.msg!.msg)
               
                return

            }
            
        })

    }
    
}
